﻿/*******************************************************************************
 **  Name:                                        **
 **  Description:                                                             **
 **                                                                           **
 **  CDDL: Open Source Initiative (OSI) Approved License                            **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  The contents of this file are subject to the terms of the CDDL:          **
 **  Common Development and Distribution License (the "License").             **
 **  You may not use this file except in compliance with the License.         **
 **                                                                           **
 **  You can obtain a copy of the license at $PROJECT_ROOT/LICENSE            **
 **  or http://www.opensolaris.org/os/licensing.  This code is Open Source    **
 **  and you are free to use it within the confines of the license, even      **
 **  for your own closed-source commercial projects, as long as you follow    **
 **  the terms set forth in the CDDL.                                         **
 **                                                                           **
 **  When distributing Covered Code, include this CDDL HEADER in each         **
 **  file and include the License file at $PROJECT_ROOT/LICENSE.              **
 **  If applicable, add the following below this CDDL HEADER, with the        **
 **  fields enclosed by brackets "[]" replaced with your own identifying      **
 **  information: Portions Copyright [yyyy] [name of copyright owner]         **
 **                                                                           **
 ******************************************************************************/
// Created on November 1, 2010, 7:25 AM
// Modified $Date$ by $Author$
// $Id$

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;

namespace sat1baf1
{
    public partial class CharacterCreatorForm : Form
    {
        List<Origin>  _origins;
        enum CCSTATE { PROFESSION, ORIGIN, STATS, SKILLS, FEATS, WEALTH, GEAR, STATES };
        CCSTATE _state;
        const int maxpts = 36;
        int spentpts = 0;
        int[,] AttrTable = {
               
                {8,0,-1},
                {9,1,-1},
                {10,2,0},
                {11,3,0},
                {12,4,1},
                {13,6,1},
                {14,8,2},
                {15,11,2},
                {16,14,3},
                {17,18,3},
                {18,22,4},
                {19,-1,4}

            };
        int[] attrs = { 8, 8, 8, 8, 8, 8 };

        public CharacterCreatorForm()
        {
            InitializeComponent();
            _state = CCSTATE.PROFESSION;
            progressBar.Minimum = 0;
            progressBar.Maximum = 8;
            progressBar.Step = 1;

            InitializeData();
        }
        void InitializeData()
        {
            // Classes
            XElement careers = CareerDB.Instance.Careers;
            foreach (XElement c in careers.Elements("Class"))
            {
                XmlLog.Instance.Add((string)c);
                XmlLog.Instance.Add((string)c.Element("Name"));
                //              MessageBox.Show((string)t.Element("Name"));
                comboClasses.Items.Add((string)c.Element("Name"));
            }
            comboClasses.SelectedIndex = 0;


            // Origins
            _origins = new List<Origin>();
                // talents
            IEnumerable<XElement> talents = OriginDB.Instance.Talents;
            foreach (XElement t in talents.Elements("Talent"))
            {
                XmlLog.Instance.Add((string)t);
                XmlLog.Instance.Add((string)t.Element("Name"));
  //              MessageBox.Show((string)t.Element("Name"));
                comboTalents.Items.Add((string)t.Element("Name"));
            }
                // specialties
            IEnumerable<XElement> specs = OriginDB.Instance.Specialties;
            foreach (XElement t in specs.Elements("Specialty"))
            {
                XmlLog.Instance.Add((string)t);
                XmlLog.Instance.Add((string)t.Element("Name"));
    //            MessageBox.Show((string)t.Element("Name"));
                comboSpecialties.Items.Add((string)t.Element("Name"));
            }

            // statistics info

        }

        private void comboClasses_SelectedIndexChanged(object sender, EventArgs e)
        {
            rtClassName.Text = comboClasses.SelectedItem.ToString();
            XElement careers = CareerDB.Instance.Careers;
            comboClassSkills.Items.Clear();
            listClassAbilities.Items.Clear();
            foreach (XElement c in careers.Elements("Class"))
            {
                if ((string)c.Element("Name") == rtClassName.Text)
                {
#if DEBUG
                    XmlLog.Instance.Add("ClassChanged: Found " + rtClassName.Text + " with " );

#endif
                    MessageBox.Show("Found " + rtClassName.Text);
                    rtClassDesc.Text = (string)c.Element("Desc");
                    foreach (XElement s in c.Elements("Skills"))
                    {
                        comboClassSkills.Items.Add(s.Element("Skill").Value);
                        MessageBox.Show("Skill: " + s.Element("Skill").Value);
                    }
                    foreach (XElement a in c.Elements("Abilities"))
                    {
                        listClassAbilities.Items.Add((string)a.Element("Ability").Attribute("name"));
                    }

                    break;     
                }
            }
  //          MessageBox.Show("Setting info for " + rtClassName.Text);
 //           IEnumerable<XElement> classdata = CareerDB.Instance.FindCareerByName(comboClasses.SelectedText);
 //           MessageBox.Show((string)classdata.ElementAtOrDefault(1).Element("Class"));


        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            int ct = (int)_state; ct++; _state = (CCSTATE)ct;
            progressBar.PerformStep();
            //progressBar.Text
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            int ct = (int)_state; ct++; _state = (CCSTATE)ct;
            //progressBar.Dec
        }




    } // class CharacterCreatorForm

    public class NewAttributeSpinner : System.Windows.Forms.NumericUpDown
    {
        public NewAttributeSpinner() { }

        protected override void OnValueChanged(EventArgs ev)
        {
            base.OnValueChanged(ev);

        }


    }
}
